Skip to content

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Sep 1, 2025

On main the following leaks:

$ ./python -X showrefcount -c 'import _random; s = _random.Random(); t = type(s); t._random = s'
[42 refs, 26 blocks]

ZeroIntensity
ZeroIntensity previously approved these changes Sep 1, 2025
Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one idea.

@serhiy-storchaka
Copy link
Member

Wait, why is _random.Random mutable?

@ZeroIntensity
Copy link
Member

Probably because it would break code to change that.

@serhiy-storchaka
Copy link
Member

It became mutable in 3.9. I think this is a bug.

@picnixz
Copy link
Member Author

picnixz commented Sep 1, 2025

It became mutable in 3.9. I think this is a bug.

I was also surprised but I just didn't want to break stuff here.

@kumaraditya303
Copy link
Contributor

It became mutable in 3.9. I think this is a bug.

Yes, I think adding IMMUTABLE flag was missed while conversion, it shouldn't be a mutable type.

@kumaraditya303
Copy link
Contributor

See #88074 where most of the converted types where made immutable, same should be done for random and epoll

@picnixz picnixz marked this pull request as draft September 1, 2025 18:57
@picnixz picnixz changed the title gh-116946: fully implement GC protocol for random.Random gh-116946: add Py_TPFLAGS_IMMUTABLETYPE to _random.Random Sep 2, 2025
@picnixz
Copy link
Member Author

picnixz commented Sep 2, 2025

@rhettinger Does this change satisfy you? do you want this to be backported?

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vstinner
Copy link
Member

vstinner commented Sep 2, 2025

do you want this to be backported?

Please don't backport this change. It would be surprising that a class becomes immutable in 3.x.y bugfix release.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I would prefer a single large PR that fixes the 3.9 error by making all converted types immutable.

@picnixz picnixz merged commit 51244ba into python:main Sep 3, 2025
54 of 63 checks passed
@picnixz picnixz deleted the fix/gc/random-heap-types-116946 branch September 3, 2025 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants